package com.xu.mylol.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.xu.mylol.R;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/8.
 */
public class TabAdapter extends FragmentPagerAdapter{
    private ArrayList<Fragment> data;
    private Context context;
    //    private  String[] titles;
    String title1 = "新闻";
    String title2 = "资料";
    String title3 = "查询";
    String title4 = "视频";
    String title5 = "图库";
    String[] titles = {title1, title2, title3, title4,title5};
    private int[] imageview = {R.mipmap.news,R.mipmap.ddd,R.mipmap.query,R.mipmap.video,R.mipmap.image};

    public TabAdapter(FragmentManager fm, ArrayList<Fragment> data, Context context) {
        super((fm));
        this.data = data;
        this.context = context;
    }


    @Override
    public Fragment getItem(int position) {

        return data.get(position);
    }

    @Override
    public int getCount() {
        return data.size();


    }

    @Override
    public CharSequence getPageTitle(int position) {
//        return titles[position];
        return null;
    }

    public View getTabview(int postion) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab, null);
        TextView textView = (TextView) view.findViewById(R.id.tab_tv);
        ImageView imageView = (ImageView) view.findViewById(R.id.tab_iv);
        textView.setText(titles[postion]);
        imageView.setImageResource(imageview[postion]);
        return view;

    }

}
